package com.fileDemo;


import java.io.FileOutputStream;
import java.io.ObjectOutputStream;
import java.io.Serializable;

/**
 * Created with IntelliJ IDEA.
 *
 * @Author: FENGYiMing
 * @Date: 2024/04/10/10:37
 * @Description:
 */
public class ObjectOutputStream01 {
    public static void main(String[] args) throws Exception {
        ObjectOutputStream oop = new ObjectOutputStream(new FileOutputStream("e:/oop.bat"));
        oop.writeInt(100);
        oop.writeBoolean(true);
        oop.writeChar('a');
        oop.writeFloat(1.1f);
        oop.writeUTF("沙漠金额");
        oop.writeObject(new Dog("旺财", 12));
        oop.close();
    }


}

class Dog implements Serializable {
    private String name;
    private int age;

    public Dog(String name, int age) {
        this.name = name;
        this.age = age;
    }

    public String getName() {
        return name;
    }

    public void setName(String name) {
        this.name = name;
    }

    public int getAge() {
        return age;
    }

    public void setAge(int age) {
        this.age = age;
    }

    @Override
    public String toString() {
        return "Dog{" +
                "name='" + name + '\'' +
                ", age=" + age +
                '}';
    }

    public void speak() {
        System.out.println("小狗叫》》》");
    }
}
